<template>
<van-form @submit="onSubmit">
    <van-field v-model="username" name="用户名" label="用户名" placeholder="用户名" :rules="[{ required: true, message: '请填写用户名' }]" />
    <van-field v-model="password" type="password" name="密码" label="密码" placeholder="密码" :rules="[{ required: true, message: '请填写密码' }]" />
    <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">提交</van-button>
    </div>
    <!-- <van-button type="primary" v-on:click='login()'>提交</van-button> -->
</van-form>
</template>

<script>
import {
    LOGIN
} from "@/api/login";
import request from "@/utils/request";
import Cookies from "js-cookie";
export default {
    data() {
        return {
            username: "kingxuan",
            password: "123456"
        };
    },
    created() {},

    methods: {
        onSubmit(values) {
            // commit(values) {
            console.log("submit", values);
            const obj = {
                username: this.username,
                password: this.password
            };
            const that = this;
            LOGIN(obj)
                .then(function (res) {
                    if (res.status == "200") {

                        //用户数据储存
                        // console.log(res.data.user,'useruseruser')
                        // that.$store.state.user = res.data.user;

                    
                        that.$router.push({
                            path: "/index"
                        });
                    } else {
                        alert(res.msg);
                    }
                })

                .catch(function (error) {
                    console.log(error);
                });
        }
    }
};
</script>
